#include<bits/stdc++.h>
using namespace std;
int all[1010],ans=-1e9,n,maxsc[1010];
int red,blue;
void dfs(int dep,int sum){
    if(sum+maxsc[dep]<=ans) return;
    if(dep>n)
        ans=max(ans,sum);
    else{
        int tem=red,tsum=sum+(red==all[dep])*red;
        red=all[dep];
        dfs(dep+1,tsum);
        red=tem;
        tem=blue,tsum=sum+(blue==all[dep])*blue;
        blue=all[dep];
        dfs(dep+1,tsum);
        blue=tem;
    }
}
signed main(){
    //freopen("color.in","r",stdin);
    //freopen("color.out","w",stdout);
    int T,i;
    scanf("%d",&T);
    while(T--){
        memset(maxsc,0,sizeof maxsc);
        ans=-1e9,red=blue=-1e9;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
            scanf("%d",all+i);
        for(i=n;i>0;i--){
            maxsc[i]+=all[i];
            maxsc[i]+=maxsc[i+1];
        }
        dfs(1,0);
        printf("%d\n",ans);
    }
    return 0;
}
